import type { TableColumn, FormField } from '@/components'
import { ref } from 'vue'
import { competentDeptInfo } from '@/api/spotCheck/spotCheck'

competentDeptInfo().then((res) => {
  fields.value.forEach((i) => {
    if (i.key === 'competentDeptId') {
      i.attrs.data = res.data
    }
  })
})

export const fields = ref([
  {
    key: 'year',
    label: '年份',
    tag: 'el-date-picker',
    attrs: {
      format: 'YYYY',
      dateFormat: 'YYYY',
      valueFormat: 'YYYY',
      placeholder: '请选择',
      type: 'year'
    }
  },
  {
    key: 'state',
    label: '是否推送',
    tag: 'MSelect',
    attrs: {
      options: [
        {
          label: '是',
          value: 1
        },
        {
          label: '否',
          value: 0
        }
      ]
    }
  },
  {
    key: 'competentDeptId',
    label: '主管部门',
    tag: 'el-tree-select',
    placeholder: '请选择',
    attrs: {
      style: 'width: 210px',
      data: [],
      props: {
        label: 'deptName',
        value: 'deptId',
        children: 'children'
      },
      clearable: true,
      checkStrictly: true,
      filterable: true
    }
  }
])

export const columns: TableColumn[] = [
  {
    key: 'years',
    label: '年份'
  },
  {
    key: 'compDept',
    label: '主管单位'
  },
  {
    key: 'sorgName',
    label: '社会组织名称'
  },

  {
    key: 'time',
    label: '审批时间'
  },

  {
    key: 'status',
    label: '状态',
    slot: true
  },
  {
    key: 'state',
    label: '是否推送',
    slot: true
  },
  {
    key: 'actions',
    label: '操作',
    slot: true,
    fixed: 'right',
    width: 100
  }
]

export const dialogFields: FormField[] = [
  {
    key: 'typeId',
    label: '限制时间',
    tag: 'el-date-picker',
    attrs: {
      type: 'datetimerange',
      startPlaceholder: '开始时间',
      endPlaceholder: '结束时间',
      format: 'YYYY-MM-DD HH:mm:ss',
      dateFormat: 'YYYY/MM/DD ddd',
      timeFormat: 'A hh:mm:ss'
    },
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  },
  {
    key: 'labelName',
    label: '账户名称',
    tag: 'ElInput',
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  },
  {
    key: 'labelRule',
    label: '使用人',
    tag: 'ElInput',
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  },
  {
    key: 'labelPattern',
    label: '删除阈值',
    tag: 'ElInput',
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  }
]
